package com.ncst.mvcweb;

public class OrderStateDemo {
    public static void main(String[] args) {
        Order order = new Order(new CreateState());
        order.handle();
        order.setState(new PayState());
        order.handle();
        order.setState(new SendState());
        order.handle();
        order.setState(new ReceiveState());
        order.handle();
        order.setState(new CancelState());
        order.handle();
    }
}

interface State {
    void handle();
}

class CreateState implements State {
    @Override
    public void handle() {
        System.out.println("创建订单");
    }
}

class PayState implements State {
    @Override
    public void handle() {
        System.out.println("支付订单");
    }
}

class SendState implements State {
    @Override
    public void handle() {
        System.out.println("发货");
    }
}

class ReceiveState implements State {
    @Override
    public void handle() {
        System.out.println("收货");
    }
}

class CancelState implements State {
    @Override
    public void handle() {
        System.out.println("取消订单");
    }
}

class Order {
    private State state;

    public Order(State state) {
        this.state = state;
    }

    public void setState(State state) {
        this.state = state;
    }

    public void handle() {
        state.handle();
    }
}
